package draw;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;

/**
 * 创建时间：2018年02月06日14:42 <br>
 * 作者：fuchaoyang <br>
 * 描述：
 */

public class DrawView extends View {
  private String text = "hello";
  Paint mPaint;

  public void setText(String text) {
    this.text = text;
  }

  public DrawView(Context context) {
    this(context, null);
  }

  public DrawView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    mPaint = new TextPaint();
    mPaint.setColor(Color.BLUE);
    mPaint.setTextSize(40);
  }

  private IDraw mIDraw;

  public void setIDraw(IDraw IDraw) {
    mIDraw = IDraw;
  }

  @Override protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawText(text, 0, 100, mPaint);
    if (mIDraw != null) {
      mIDraw.onDraw(canvas);
    }
  }

  public interface IDraw {
    void onDraw(Canvas canvas);
  }
}
